﻿using System;

namespace Events
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            // create obj of subscriber class
            Subscriber subscriber = new Subscriber();

            Publisher publisher = new Publisher();

            // handle the event(or) subscribe to event
            publisher.myEvent += subscriber.Add;
            // invoke the event
            publisher.RaiseEvent(10, 20);

            // Auto-Implemented Events
            Publisher2 p2 = new Publisher2();
            p2.myEvent += subscriber.Add;
            // invoke the event
            p2.RaiseEvent(10, 20);
            p2.RaiseEvent(4, 3);

            // Anonymous Methods
            p2.myEvent += delegate(int a, int b) { Console.WriteLine(a / b); };

            Console.ReadKey();
        }
    }
}